package main

import (
	"books/models"

	"github.com/wailsapp/wails/v2/pkg/runtime"
)

func (a *App) GetBooks(name string, author string, category_id uint64, available bool) []models.Book {
	books, err := models.GetBooks(name, author, category_id, available)
	if err != nil {
		runtime.LogError(a.ctx, err.Error())
		return nil
	}

	return books
}

func (a *App) CreateBook(name, author string, category_id uint64, publication_year int, available int) error {
	user := models.Book{
		Name:            name,
		Author:          author,
		CategoryID:      category_id,
		PublicationYear: publication_year,
		Available:       available,
	}

	return user.CreateBook()
}
